﻿using FileHelpers;

namespace SecurityModule.Parsers.Format2014
{
    /// <summary>
    /// Represents a line in the IDOR address file as of 2014 to be returned when parsing CSV files using <see cref="AddressParser"/> which uses <see cref="FileHelperEngine{T}"/>.
    /// </summary>
    [DelimitedRecord(";")]
    public class AddressLine
    {
        [FieldOrder(1)]
        [FieldConverter(typeof(AccountNumberConverter))]
        public int AccountNumber;
        [FieldOrder(2)]
        public int Site { set; get; }
        [FieldOrder(3)]
        public string LocationCode { set; get; }
        [FieldOrder(4)]
        public int SIC { set; get; }
        [FieldOrder(5)]
        public string CompanyName { set; get; }
        [FieldOrder(6)]
        public string CompanyName2 { set; get; }
        [FieldOrder(7)]
        public string Address1 { set; get; }
        [FieldOrder(8)]
        public string Address2 { set; get; }
        [FieldOrder(9)]
        public string City { set; get; }
        [FieldOrder(10)]
        public string State { set; get; }
        [FieldOrder(11)]
        public string Zip { set; get; }
        [FieldOrder(12)]
        public string U1 { set; get; }
        [FieldOrder(13)]
        public string U2 { set; get; }

        public override string ToString()
        {
            return AccountNumber + ", " + Site + ", " + CompanyName;
        }

        public class AccountNumberConverter : ConverterBase
        {
            public override object StringToField(string from)
            {
                return int.Parse(from.Replace("-", ""));
            }
        }
    }
}
